home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nannws14.zip / MININET.PRG < prev    next >
Text File  |  1987-05-28  |  13KB  |  376 lines

  1. * MININET.PRG
  2. *
  3. * Date:       April, 1987
  4. * Author:  David Morgan
  5. * Notes:   Mini-program to demonstrate, in Clipper,
  6. *           1)  when private data control is and isn't needed 
  7. *               on a network, and
  8. *           2)  programming techniques for using the two tools
  9. *               that achieve private control (namely, locks on 
  10. *               files under shared use; and exclusive use)
  11. *
  12. *        To compile and link, required files are: 
  13. *             MININET.PRG  LOCKS.PRG  CLIPPER.LIB  DBU.LIB
  14. *           Syntax:
  15. *             CLIPPER MININET
  16. *             LINK MININET,,,CLIPPER DBU
  17. *
  18. *           Uses test file STATES.DBF containing records
  19. *            for the 13 original states
  20. *
  21. *           Structure of STATES.DBF
  22. *
  23. *           Field  Field Name  Type       Width    Dec
  24. *           1  ST_ABBREV   Character      2
  25. *           2  ST_NAME     Character     20
  26. *           3  ST_CAPITAL  Character     20
  27. *           4  ST_UPDATED  Numeric       10
  28. *
  29. *              4th field is update marker (signature field)
  30. *               for flagging all writes to the record
  31. *
  32. *           Corresponding Index Files     Key Expression
  33. *           STATES1.NTX                   ST_ABBREV
  34. *           STATES2.NTX                   ST_NAME 
  35. *           STATES3.NTX                   ST_CAPITAL
  36. *
  37.  
  38. CLEAR
  39. SET PROCEDURE TO LOCKS
  40. SET MESSAGE TO 23
  41. SET KEY -1 TO VIEW_FILE
  42. SET EXCLUSIVE OFF
  43. bell = CHR(7)
  44. st_list = "AK AL AR AZ CA CO CT DC DE FL GA HI IA ID IL IN KS ";
  45.         + "KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV ";
  46.         + "NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV WY "
  47. IF NET_USE("STATES",.F.,5)
  48.  SET INDEX TO STATES1,STATES2,STATES3
  49. ELSE
  50.  ? 'File not avaiable for shared use. Program terminated.'
  51.  RETURN
  52. ENDIF
  53. @ 1,0 SAY CENTER("===  MININET: Miniature Clipper Network Application  ===",80)
  54. @ 4,45 SAY 'F2 key to view file contents'
  55.  
  56. DO WHILE .T.
  57.  @  8,25 PROMPT "1. ADD RECORD"  MESSAGE CENTER(">>> NO LOCKING Needed for APPEND BLANK <<<",80)
  58.  @  9,25 PROMPT "2. EDIT RECORD"  MESSAGE CENTER(">>> Record Locking Needed to REPLACE <<<",80)
  59.  @ 10,25 PROMPT "3. EXAMINE/PRINT/REPORT"  MESSAGE CENTER(">>> NO LOCKING Needed for These Passive Operations <<<",80)
  60.  @ 11,25 PROMPT "4. MAINTAIN FILE"  MESSAGE CENTER(">>> File Locking or Exclusive Use Needed <<<",80)
  61.  @ 12,25 PROMPT "5. QUIT"
  62.  MENU TO choice1
  63.  @ 8,0 CLEAR TO 12,79
  64.  @ 23,0
  65.  DO CASE
  66.   CASE choice1 = 1
  67.    DO ADD
  68.   CASE choice1 = 2
  69.    DO EDIT
  70.   CASE choice1 = 3
  71.    SET INDEX TO STATES2
  72.    DO EXAMINE
  73.    SET INDEX TO STATES1,STATES2,STATES3
  74.   CASE choice1 = 4
  75.    DO MAINTAIN
  76.   CASE choice1 = 5
  77.    EXIT
  78.  ENDCASE
  79.  @ 15,0 CLEAR TO 20,79
  80. ENDDO
  81. CLEAR
  82. RETURN
  83. *======================================================================================================================
  84.  
  85. PROCEDURE ADD
  86. m_abbrev='  '
  87. @ 15,10 SAY 'Give abbreviation for this state' GET m_abbrev VALID CHECK_ST()
  88. READ
  89. IF EMPTY(m_abbrev)
  90.  RETURN
  91. ELSE
  92.  IF ADD_REC(5)
  93.   REPLACE st_abbrev WITH UPPER(m_abbrev)      && ADD_REC already RLOCKed for us
  94.   @ 23,0 SAY CENTER("Record added.",80)
  95.  ELSE
  96.   @ 23,0 SAY CENTER("Can't add record.",80)
  97.  ENDIF
  98.  ?? bell
  99.  INKEY(1)
  100.  RETURN
  101. ENDIF
  102.  
  103. FUNCTION CHECK_ST                             && must be a real state
  104. m_abbrev = UPPER(m_abbrev)                    && not already in file
  105. SEEK m_abbrev
  106. RETURN( IF(.NOT.FOUND().AND.(m_abbrev+' ')$st_list,.T.,.F.) )
  107. *----------------------------------------------------------------------------------------------------------------------
  108.  
  109. PROCEDURE EDIT
  110.  DO WHILE .T.                                &&         ^
  111.   *************************************                    &&        |
  112.   * Select a record to edit                        &&          |
  113.   *************************************                    &&         |
  114. *-contingency branch point A              <-------------------------------------    |
  115.   choice2=0                                                             &&      |   |
  116.   choice3=0                                &&      |   |
  117.   m_abbrev = '  '                            &&      |   |
  118.   @ 15,10 SAY 'Which state do you want (give abbreviation)?' GET m_abbrev &&    |   |
  119.   READ                                    &&      |   |
  120.   @ 15,10                                &&      |   |
  121.   SEEK UPPER(m_abbrev)                            &&      |   |
  122.   IF .NOT.FOUND()                            &&      |   |
  123.    @ 15,10 SAY 'No such state.'                     &&      |   |
  124.    INKEY(2)                                &&      |   |
  125.    @ 15,0 CLEAR TO 20,79                        &&      |   |
  126.    EXIT                                    &&      |   |
  127.   ENDIF                                    &&      |   |
  128.   *************************************                    &&      |   |
  129.   * Edit selected record                        &&      |   |
  130.   *************************************                    &&      |   |   
  131.   DO WHILE .T.                                &&      |   |
  132. *-contingency branch point B          <----------------------------------------------
  133.    m_updated = st_updated                        &&      |   |   |
  134.    m_name = st_name                            &&      |   |   |
  135.    m_capital = st_capital                        &&      |   |   |
  136.    @ 16,10 SAY 'State abbreviation: '+st_abbrev                &&      |   |   |
  137.    @ 18,10 SAY 'Edit state name:    ' GET m_name            &&      |   |   |
  138.    @ 19,10 SAY 'Edit state capital: ' GET m_capital            &&      |   |   |
  139.    READ                                    &&      |   |   |
  140.    DO WHILE .T.                                &&      |   |   |
  141. *-contingency branch point C                        &&      |   |   |
  142.     ***************************************                &&      |   |   |
  143.     * Can't LOCK record - optional branches                &&      |   |   |
  144.     *************************************** &&                        <--------    |   |   |
  145.     IF .NOT.REC_LOCKER(5)                        &&  |   |   |   |
  146.      @ 18,0                                &&  |   |   |   |
  147.      @ 19,10 SAY 'Record NOT AVAILABLE now. Choose a contingency plan: '&&  |   |   |   |
  148.      @ 20,12 PROMPT "1. Retry the lock. Maybe it will free up." &&__________|   |   |   |
  149.      @ 21,12 PROMPT "2. Go back and try locking a different record." &&_________|   |   |
  150.      @ 22,12 PROMPT "3. Abort. Leave edit session, back to main menu."  &&__________|   |
  151.      MENU TO choice2                            &&        |   |
  152.      @ 19,0 CLEAR TO 22,79                        &&        |   |
  153.                         DO CASE            && branch control
  154.                          CASE choice2=1        &&        |   |
  155.                           LOOP            && to pt C direct
  156.                          CASE choice2=2        &&        |   |
  157.                           EXIT            && to pt A indirect
  158.                          OTHERWISE        &&        |   |
  159.                           RETURN        &&        |   |
  160.                         ENDCASE            &&        |   |
  161.     ENDIF                                &&        |   |
  162.     *********************************************            &&        |   |
  163.     * Record contents altered - optional branches            &&        |   |
  164.     *********************************************            &&        |   |
  165.     IF m_updated <> st_updated                        &&        |   |
  166.      UNLOCK                                && relinquish record
  167.      @ 18,0                                &&        |   |
  168.      @ 19,10 SAY "You LOCKED record BUT it's CHANGED. Choose a contingency plan: "&&|   |
  169.      @ 20,12 PROMPT "1. Let me re-edit the new contents of current record." &&__________
  170.      @ 21,12 PROMPT "2. Put my changes in TEMP file. Apply to main file later." &&  |
  171.      @ 22,12 PROMPT "3. Abort. Leave edit session, back to main menu." &&___________|
  172.      MENU TO choice3
  173.      @ 19,0 CLEAR TO 22,79
  174.                         DO CASE            && branch control
  175.                          CASE choice3=1
  176.                           EXIT            && to pt B direct
  177.                          CASE choice3=2
  178.                           *DO TEMP_STORE        && your routine
  179.                           RETURN
  180.                          OTHERWISE
  181.                           RETURN
  182.                         ENDCASE
  183.     ENDIF
  184.   *************************************
  185.   * REPLACE fields in locked record
  186.   *************************************
  187.     REPLACE st_name WITH m_name
  188.     REPLACE st_capital WITH m_capital
  189.     REPLACE st_updated WITH st_updated+1
  190.     UNLOCK
  191.     @ 23,0 SAY CENTER('Data Written To File',80)
  192.     ?? bell
  193.     INKEY(1)
  194.     RETURN          && edit has been completed
  195.    ENDDO :C
  196.                         IF choice2=2    && branch control
  197.                          EXIT        && to pt A direct
  198.                         ENDIF
  199.   ENDDO :B
  200.  ENDDO :A
  201. RETURN
  202. *----------------------------------------------------------------------------------------------------------------------
  203.  
  204. PROCEDURE EXAMINE
  205. PRIVATE top,left,bottom,right,row,end_file
  206. top    = 11
  207. left   = 17
  208. bottom = 20
  209. right  = 60
  210. SAVE SCREEN
  211. CLEAR
  212. TEXT
  213.  You can read through a lock. Locks at other stations don't affect
  214.   passive operations like:
  215.  
  216.   LIST  SEEK/SKIP/GOTO  REPORT  @..SAY <fieldname>
  217.  
  218.  And this station doesn't